<?php
session_start();
$_SESSION['controller'] = 'index';
$_SESSION['action'] = 'index';
$_SESSION['article'] = '0';
header('Content-Type: text/html; charset=utf-8');
error_reporting (E_ALL);
define ('DIR', DIRECTORY_SEPARATOR) ;
$sitePath = realpath(dirname(__FILE__) . DIR . '..' . DIR) . DIR ;
define ('SITEPATH', $sitePath) ;
require_once 'includs/startup.php' ;
$registry = new Access_Registry ;
$template = new Access_Template($registry) ;
$registry->set ('view', $template) ;
require_once 'app/access/db.php' ;
$db = new Access_Db ;
$router = new Access_Router($registry);
$registry->set('sitePath', DIR . $db->path) ; 
$registry->set ('router', $router);
$registry->set('controllersPath', 'app/controller') ;
$router->setPath ($registry->get('controllersPath')) ;
$role = new Access_Acl();
if(isset($_POST['submit_login']))
{
    require 'app/views/login.php';
}
if(isset($_POST['submit_out']))
{
    require 'app/views/out.php';
}
$user = new Models_User();
if($user->isAuth()) //=================================================auth user======
{
    $authMenu = '';
    $userName = $_COOKIE['login'];
    $outMenu = '<li class="divider"></li>
                <li><form action="/" class="form-horizontal"  method="POST">
                <div class="control-group alert alert-info" style="margin-bottom: 0px;">
                    <label class="control-label"><i class="icon-share"></i> For signout, press: </label>
                    <div class="controls">
                        <input type="submit" class="btn btn-danger" name="submit_out" value="Out">
                    </div>
                </div>
                </form></li>';
    $userId = $_COOKIE['user_id'];
} else {
    $userName = 'Guest';
    $authMenu = '<li class="btn btn-success" style="margin: 0;">
                    <a style="z-index: 9;" href="#login-box" class="login-window"><i class="icon-tasks"></i> Login</a>
                 </li>
                 <li class="btn btn-info" style="margin: 0;">
                    <a  href="/' . $db->path . 'user/registration"><i class="icon-play-circle"></i> Register</a>
                 </li>';
    $outMenu = '<li class="divider"></li>
                <div class="alert alert-info" style="margin-bottom: 0px;">Please, login or register.</div>';
    $userId = '1';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="author" content="Dmitry Yermolayev" />
    <meta name="description" content="Site of university of gas and oil" />
    <meta name="keywords" content="gas,oil,university,ivano-frankivsk" />
    <title>Ivano-Frankivsk national technical university of oil and gas</title>
    <link rel="stylesheet" type="text/css" href="/<?php $db->printPath(); ?>public/css/mainstyle.css" />
    <link rel="stylesheet" type="text/css" href="/<?php $db->printPath(); ?>libs/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="/<?php $db->printPath(); ?>public/css/login.css"/>
    <script type="text/javascript" src="/<?php $db->printPath() ; ?>libs/ckeditor/ckeditor.js"></script>
    <script src="/<?php $db->printPath() ; ?>libs/ckeditor/_samples/sample.js" type="text/javascript"></script>
    <link href="/<?php $db->printPath() ; ?>libs/ckeditor/_samples/sample.css" rel="stylesheet" type="text/css" />
    <script src="/libs/jquery/jquery.js" type="text/javascript"></script>
    <script src="/libs/carousel/jcf.js"></script>
    <script src="/<?php $db->printPath(); ?>public/js/login.js" type="text/javascript"></script>
    <script src="/libs/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/<?php $db->printPath() ; ?>libs/jpages/jPages.css">
    <link rel="stylesheet" href="/<?php $db->printPath() ; ?>libs/jpages/animate.css">
    <script src="/<?php $db->printPath() ; ?>libs/jpages/jPages.js"></script>
    <link rel="stylesheet" href="/<?php $db->printPath() ; ?>libs/blueimp/css/bootstrap-image-gallery.min.css">
    <link rel="stylesheet" href="/<?php $db->printPath() ; ?>libs/carousel/carousel.css">
    <link rel="shortcut icon" href="/<?php $db->printPath(); ?>public/ico/favicon.ico">
</head>
    <body>
        <div class="container">
            <?php 
                require_once 'app/views/ie.php';//<================================IE MESAGE====
                require_once 'app/views/header.php';//<============================HEADER=======
            ?>                       
        </div>
        <div class="container">
            <div class="navbar">
                <div class="navbar-inner">
                    <div class="container">
                        <a class="brand" href="/">
                            <span class="cdn-brand">IFNTUOG</span>
                        </a>
                        <div class="nav-collapse">
                            <ul class="nav nav-pills">
                                <?php
                                    echo $authMenu; //<=========================================AUTH MENU=====
                                ?>
                                <li>
                                    <div class="btn-group" style="padding: 0; margin: 0;">
                                      <button class="btn btn-info dropdown-toggle" style="height: 53px;" data-toggle="dropdown">
                                          <i class="icon-user icon-white"></i> <?php echo $userName; ?>... 
                                          <span class="caret"></span>
                                      </button>
                                      <ul class="dropdown-menu" style="z-index: 99;">
                                        <li style="z-index: 99;"><a href="/<?php $db->printPath(); ?>user">Profile</a></li>
                                        <?php echo $outMenu; ?>
                                      </ul>
                                    </div>
                                </li>
                            </ul>
                            <div class="navbar-search pull-right">
                                <div id="lang">
                                    <a href="#"><div class="eng"></div></a>
                                    <a href="http://nung.edu.ua"><div class="ua"></div></a>
                                </div>
                            </div>
                            <form class="navbar-search pull-right" method="POST" action="/<?php $db->printPath(); ?>search">
                                <input class="search-query span2" type="text" name="word" placeholder="Search">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="navbar navbar-top-menu">
                <div class="navbar-inner" style="background-color: white;">
                    <div class="container">
                        <?php
                            require_once 'app/views/topmenu.php';//<================TOP_MENU======
                        ?>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="span9">
                        <?php
                            $userRole = $role->getUserRoles($userId);
                            $perm = $role->getRolePermission($userRole);
                            if($role->hasPermission($perm))
                            {
                                $router->delegate();//<=================================CONTENT==========  
                            } else {
                                echo '<div class="alert alert-danger">
                                        <h3><i class="icon-exclamation-sign"></i> Error!</h3>
                                        <p>An error has occurred, the cause may be any of the following:</p>
                                        <ul>
                                        <li>The page you requested does not exist.</li>
                                        <li>You are not authorized to view this page.</li>
                                        <li>We are now working on the site.</li>
                                        <li>You are not activated user.</li>
                                        </ul>
                                        <p>Sorry for the inconvenience.</p>
                                      </div>';
                                echo '<span style="margin-left: 120px;"><img src="/' . $role->path . 'public/img/admin/error.png"></span>';
                            }
                        ?>
                </div>
                <div class="span3">
                    <div class="">
                        <?php
                            require_once 'app/views/menu.php';//====================SIDE MENU==========
                            //require_once 'app/views/baner.php';
                        ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="container">
            <?php
                require_once 'app/views/footer.php';//<=============================FOOTER========
            ?>
        </div>
            <?php
                require 'app/views/loginbox.php';//============================LOGIN-BOX======
            ?>
    </body>
</html>